package com.atguigu.guli.servicevod.controller;

import com.atguigu.guli.servicevod.service.ServiceVideoService;
import com.atguigu.servicebase.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@Api(tags = "阿里云视频点播微服务")
@CrossOrigin //跨域
@RestController
@RequestMapping("/admin/vod/video")
public class VideoController {

    @Autowired
    private ServiceVideoService videoService;

    @PostMapping("upload/{courseId}/{videoId}")
    public R uploadVideo(
            @ApiParam(name = "courseId", value = "课程ID", required = true)
            @PathVariable String courseId,
            @ApiParam(name = "videoId", value = "视频ID", required = true)
            @PathVariable String videoId,
            @ApiParam(name = "file", value = "文件", required = true)
            @RequestParam("file") MultipartFile file){
        String videoSourceId = videoService.uploadVideo(courseId, videoId, file);
        log.info("视频上传成功");
        return R.ok().message("视频上传成功").data("videoSourceId", videoSourceId);
    }

    @DeleteMapping("{courseId}/{videoId}")
    public R removeVideo(
            @ApiParam(name = "courseId", value = "课程ID", required = true)
            @PathVariable String courseId,
            @ApiParam(name = "videoId", value = "视频ID", required = true)
            @PathVariable String videoId){
        videoService.removeVideo(courseId, videoId);
        log.info("视频删除成功");
        return R.ok().message("视频删除成功");
    }

}
